import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

/** \class main
* \brief Contains functions that check properties of integers
* \author Ali Can, Aydan, Behçet, Berkin, Elizabeth, Mert, Yasemin
* \version 1.0
*/
public class main {
	
	/**
	* \brief Calls the integer property functions written by group members and prints the result on screen
	*/
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.println("Please enter an integer to see its properties");
		int number = input.nextInt();
		System.out.println("Perfect square: " + alican_isSquare(number));
		System.out.println("Prime number: " + ecr_isPrime(number));
    	System.out.println("Palindrome: "+ behcet_isPalindrome(number));
		System.out.println("Perfect number: " + berkin_isPerfect(number));
        System.out.println("Even number: " + mert_isEven(number));
        System.out.println("Narcissistic: " + yas_isNarcissistic(number));
        System.out.println("Odd number: " + aydan_isOdd(number));
	}
	
	/**
	* \brief Checks if the given integer is a perfect square
	* \param number Integer to check
	* \return True if input is perfect square, false otherwise
	*/
	public static boolean alican_isSquare(int number){
		int k = (int)Math.sqrt(number);
		return k*k==number;
		
	}
   	
	/**
	* \brief Checks if the given integer is a prime number
	* \param number Integer to check
	* \return True if input is prime number, false otherwise
	*/
   public static boolean ecr_isPrime(int number){
		if (number%2 == 0) {	//check evenness
			return false;
		} else {
			for (int i = 3; i*i < number; i+=2) {
				if (number%i == 0) {
					return false;
		}	}	} //end else, for, if
		return true;
	}
   
   	/**
	* \brief Checks if the given integer is a palindrome
	* \param number Integer to check
	* \return True if input is a palindrome, false otherwise
	*/
	public static boolean behcet_isPalindrome(int number){ 
		String num = Integer.toString(number);
		for(int i=0; i<num.length()/2; i++){
			if(num.charAt(i) != num.charAt(num.length()-1-i))
				return false;
		}
		return true;
	}
	
	/**
	* \brief Checks if the given integer is a perfect number(i.e the number is equal to sum of its proper positive divisors)  
	* \param num Positive integer to check
	* \return True if input is a perfect number, false otherwise
	*/
	public static boolean berkin_isPerfect(int num){
		int perfectNo = 0;
		int i;
		for (i = 1; i < num; i++) {
			if (num % i == 0) {
				perfectNo += i;
			}
		}
		if (perfectNo == num) {
			return true;
		} else {
			return false;
		}
	}
        
	/**
	* \brief Checks if the given integer is even
	* \param num Integer to check
	* \return True if input is even, false otherwise
	*/
    // function is reviewed
    public static boolean mert_isEven(int num) {
        return ( num % 2 == 0 );
    }

	/**
	* \brief Checks if the given integer is a narcissistic number
	* \param num Integer to check
	* \see powOfDigits()
	* \see listOfDigits()
	* \return True if input is a narcissistic number, false otherwise
	*/
    public static boolean yas_isNarcissistic(int num){

        List digits = listOfDigits(num);
        double totalPowerOfDigits = powOfDigits(digits);

        if(totalPowerOfDigits == num){
            return true;
        }

        return false;
    }

	/**
	* \brief Calculates sum of each digit raised to power of total number of digits
	* \param digits List of digits of the input integer
	* \return Resulting sum
	*/
    private static double powOfDigits(List digits) {
        double cube = 0;
        int sz = digits.size();
        for(int i = 0; i< digits.size(); i++){
            cube = (cube + Math.pow((Integer)digits.get(i), sz));
        }

        return cube;
    }

	/**
	* \brief Converts the given integer to a list of digits
	* \param i Integer to represent as a list of digits
	* \return Digits of the input as an array list
	*/
    private static List listOfDigits(int i) {
        List digits = new ArrayList();
        int rem = 0;
        while(i/10 >0){
            rem = i % 10;
            digits.add(rem);
            i = i/10;
        }
        rem = i;
        digits.add(rem);

        return digits;
    }

	/**
	* \brief Checks if the given integer is odd
	* \param num Integer to check
	* \return True if input is odd, false otherwise
	*/
	public static boolean aydan_isOdd(int num) {
        return num % 2 == 1;
    }
}


